﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using x.paypal.service;
using x.paypal.model;

namespace x.paypal.tests
{
    [TestClass]
    public class PayPalTests
    {
        IPayPalAdaptivePaymentService _paypalsvc;
        [TestInitialize]
        public void Init()
        {
            _paypalsvc = new PayPalAdaptivePaymentService(); 
        }

        [TestMethod]
        public void Test_That_Can_Request_Payment_From_PayPal()
        {
            string payReference = "123test";
            string currency = "USD";
            string amount = "10";
            Uri returnUrl = new Uri("http://wwww.fourworld.net");
            Uri cancelUrl = new Uri("http://wwww.fourworld.net");
            Uri ipnUrl = new Uri("http://wwww.fourworld.net");
            string seller = "finance@testfourworld.net"; 
            List<Receiver> receivers = new List<Receiver>();
            receivers.Add(new Receiver { Amount = amount, Email = seller, InvoiceId = payReference, Description="Test send $100 to Test - Money will be delivered to 0772120056" });
            var payRequest = new PayRequest().CreateRequest().WithPaymentReference(payReference).WithReturnUri(returnUrl).WithCancelUri(cancelUrl).WithIPNUri(ipnUrl).Currency(currency).ReceiverList(receivers);
            var resp = _paypalsvc.RequestPayment(payRequest);
            Assert.IsNotNull(resp); 
        }
        [TestMethod]
        public void Test_That_Can_Execute_Payment()
        {
            string paykey = "AP-4LD22756E88812235";
            var executepayRequest = new ExecutePayRequest().CreateRequest().WithPayKey(paykey);
            var resp = _paypalsvc.ExecutePayment(executepayRequest);
            Assert.IsNotNull(resp); 
        }
        [TestMethod]
        public void Test_That_Can_Get_PaymentDetails()
        {
            var paykey = "AP-56L41061FN853904D";
            var payDetails = new PaymentDetailsRequest().CreateRequest().WithPayKey(paykey);
            var resp = _paypalsvc.GetPaymentDetails(payDetails);
            Assert.IsNotNull(resp);
            Assert.AreEqual(resp.PayKey, paykey); 
        }
    }
}
